package com.xinweisi.dataserver.module.datastatistics.bettingrecord;

import com.xinweisi.dataserver.common.domain.ResponseDTO;
import com.xinweisi.dataserver.module.datastatistics.bettingrecord.dto.BettingRecordQueryDTO;
import com.xinweisi.dataserver.module.datastatistics.bettingrecord.vo.BettingRecordBaseVO;
import com.xinweisi.dataserver.module.datastatistics.bettingrecord.vo.MGBettingBaseVO;
import com.xinweisi.dataserver.module.datastatistics.bettingrecord.vo.PTBettingBaseVO;
import com.xinweisi.dataserver.util.DBNameUtil;
import com.xinweisi.dataserver.util.DateUtil;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * MemberBettingRecordController
 *
 * @author lijie1
 * @version 1.0
 * @date 2020/7/29 0029 14:15
 */
@Slf4j
@RestController
@RequestMapping("/api/sysData/bettingRecord")
public class MemberBettingRecordController {
    @Value("${startDBName}")
    private String OldDBName;

    @Autowired
    private MemberBettingRecordService memberBettingRecordService;

    @ApiOperation(value = "投注记录", notes = "投注记录")
    @RequestMapping(value = "/getData",method= RequestMethod.POST)
    public ResponseDTO<BettingRecordBaseVO> getData(@RequestBody @Valid BettingRecordQueryDTO queryDTO){
        log.info("----------投注记录----------");
        String startTime;
        if(queryDTO.getStartTime()!=null && !"".equals(queryDTO.getStartTime())){
            startTime = queryDTO.getStartTime();
        }else {
            startTime = DateUtil.getDateAll(DateUtil.getToDayInitial());
            queryDTO.setStartTime(startTime);
            queryDTO.setEndTime(DateUtil.getDateAll(DateUtil.getToDayInitialEnd()));
        }
        String endTime;
        if(queryDTO.getEndTime()!=null && !"".equals(queryDTO.getEndTime())){
            endTime = queryDTO.getEndTime();
        }else {
            endTime =queryDTO.getStartTime();
        }
        startTime = startTime.substring(0,startTime.indexOf(" "));
        endTime = endTime.substring(0,endTime.indexOf(" "));
        queryDTO.setDBNameList(DBNameUtil.getDANameList(OldDBName,startTime,endTime));
        return memberBettingRecordService.getData(queryDTO);
    }

    @ApiOperation(value = "投注记录", notes = "投注记录")
    @RequestMapping(value = "/getPTData",method= RequestMethod.POST)
    public ResponseDTO<PTBettingBaseVO> getPTData(@RequestBody @Valid BettingRecordQueryDTO queryDTO){
        log.info("----------PT投注记录----------");
        String startTime;
        if(queryDTO.getStartTime()!=null && !"".equals(queryDTO.getStartTime())){
            startTime = queryDTO.getStartTime();
        }else {
            startTime = DateUtil.getDateAll(DateUtil.getToDayInitial());
            queryDTO.setStartTime(startTime);
            queryDTO.setEndTime(DateUtil.getDateAll(DateUtil.getToDayInitialEnd()));
        }
        String endTime;
        if(queryDTO.getEndTime()!=null && !"".equals(queryDTO.getEndTime())){
            endTime = queryDTO.getEndTime();
        }else {
            endTime =queryDTO.getStartTime();
        }
        startTime = startTime.substring(0,startTime.indexOf(" "));
        endTime = endTime.substring(0,endTime.indexOf(" "));
        queryDTO.setDBNameList(DBNameUtil.getDANameList(OldDBName,startTime,endTime));
        return memberBettingRecordService.getPTData(queryDTO);
    }

    @ApiOperation(value = "投注记录", notes = "投注记录")
    @RequestMapping(value = "/getMGData",method= RequestMethod.POST)
    public ResponseDTO<MGBettingBaseVO> getMGData(@RequestBody @Valid BettingRecordQueryDTO queryDTO){
        log.info("----------MG投注记录----------");
        String startTime;
        if(queryDTO.getStartTime()!=null && !"".equals(queryDTO.getStartTime())){
            startTime = queryDTO.getStartTime();
        }else {
            startTime = DateUtil.getDateAll(DateUtil.getToDayInitial());
            queryDTO.setStartTime(startTime);
            queryDTO.setEndTime(DateUtil.getDateAll(DateUtil.getToDayInitialEnd()));
        }
        String endTime;
        if(queryDTO.getEndTime()!=null && !"".equals(queryDTO.getEndTime())){
            endTime = queryDTO.getEndTime();
        }else {
            endTime =queryDTO.getStartTime();
        }
        startTime = startTime.substring(0,startTime.indexOf(" "));
        endTime = endTime.substring(0,endTime.indexOf(" "));
        queryDTO.setDBNameList(DBNameUtil.getDANameList(OldDBName,startTime,endTime));
        return memberBettingRecordService.getMGData(queryDTO);
    }
}
